home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / FormOptions.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  5.6 KB  |  217 lines

  1. //
  2. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3. // ----------------------------------------------------
  4. //
  5. // Accessibility.js
  6. //
  7. // This command adds accessibility attributes/tags to the <input> element
  8. // attributes: tabindex, accessKey, "<lable for>|<lable>|none" and the label.
  9. // 
  10. //
  11. // Version 1.0
  12. // Added functions... TODO: use the dom to add attributes instead of pattern matching.
  13. // ----------------------------------------------------
  14.  
  15. var helpDoc = MM.HELP_objFormAccessOptions;
  16. var globalFormItem;
  17. var returnTag='';
  18.  
  19. function commandButtons() {
  20.    return new Array(MM.BTN_OK,         "setAccessibilityStr();window.close()",
  21.                     MM.BTN_Cancel,     "setReturnStr();window.close()",
  22.                     MM.BTN_Help,       "displayHelp()"    );
  23.  
  24.  
  25. }
  26.  
  27.  
  28. function isDOMRequired() { 
  29.     // Return false, indicating that this object is available in code view.
  30.     return false;
  31. }
  32.  
  33. function setFormItem(formItem) {
  34.     globalFormItem = formItem;
  35.  
  36. }
  37.  
  38. function setReturnStr(){
  39.  
  40.     returnTag=globalFormItem;
  41. }
  42.  
  43. function setAccessibilityStr()
  44. {
  45.  
  46.     initStr= globalFormItem;
  47.     rtnStr= initStr;
  48.  
  49.  
  50. ////////////////////////////////////////////////////////////////
  51. // Attributes: Compose initStr with the attributes that have a value
  52. // Possible attributes are: accesskey, tabindex and id (when <label for=""> is used.)
  53.  
  54.  
  55. // if 'accesskey attribute' has a value, apply it to the initStr
  56.  
  57.     acsKeyValue=document.forms[0].accesskey.value;
  58.     if( (acsKeyValue == null) || (acsKeyValue == "") ){} 
  59.     else {
  60.         initStr= addAttribute("accesskey", acsKeyValue, initStr);
  61.     }
  62.  
  63. // if 'tabindex attribute' has a value, apply it to the initStr
  64.  
  65.     tabIndexValue=document.forms[0].tabindex.value;
  66.  
  67.     if( (tabIndexValue == null) || (tabIndexValue == "") ){} 
  68.     else {
  69.         initStr= addAttribute("tabindex", tabIndexValue, initStr);
  70.     }
  71.  
  72. // if style requested is to include the 'for' attribute, then add id='elementName' to initStr
  73.  
  74.     elementName= getElement(initStr);
  75.     if (document.forms[0].labeloption[1].checked) {
  76.  
  77.         initStr= addAttribute("id", elementName, initStr);
  78.     }
  79.  
  80. ////////////////////////////////////////////////////////////////
  81. // Dialog Options: Label Style and Position
  82. // resolve 'style option' and position for <LABEL> tag.
  83.  
  84.     labelStyle='none';
  85.     // style CASE: 'wrap with label'  
  86.     if (document.forms[0].labeloption[0].checked) {
  87.         labelStyle='0';
  88.         
  89.         // position 'before/after' CASE
  90.         if (document.forms[0].position[1].checked) {
  91.             rtnStr= "<LABEL>" + initStr + document.forms[0].label.value + "</LABEL>";
  92.         } 
  93.         else {
  94.             if (document.forms[0].position[0].checked) {
  95.                 rtnStr= "<LABEL>" + document.forms[0].label.value + initStr + "</LABEL>";
  96.             }
  97.         }
  98.     }
  99.  
  100.     // style CASE: 'wrap with label and use 'for' attribute'  
  101.     if (document.forms[0].labeloption[1].checked) {
  102.         labelStyle='1';
  103.         elementName= getElement(initStr);
  104.  
  105.         // position CASE: 'before/after' 
  106.         if (document.forms[0].position[1].checked) {
  107.             rtnStr= initStr + "<LABEL for=" + "\"" + elementName + "\">"+ document.forms[0].label.value + "</LABEL>";
  108.         } 
  109.         else {
  110.             if (document.forms[0].position[0].checked) {
  111.                 rtnStr= "<LABEL for=" + "\"" + elementName + "\">"+ document.forms[0].label.value + "</LABEL>" + initStr;
  112.             }
  113.         }
  114.     }
  115.  
  116.     if(    labelStyle == 'none'){
  117.     labelStyle= '2';
  118.  
  119.         // position CASE: 'before/after' 
  120.         if (document.forms[0].position[1].checked) {
  121.             rtnStr= initStr + document.forms[0].label.value;
  122.         } 
  123.         else {
  124.             if (document.forms[0].position[0].checked) {
  125.                 rtnStr= document.forms[0].label.value + initStr;
  126.             }
  127.         }    
  128.     }
  129.     setLabelPref(labelStyle);
  130.     returnTag= rtnStr;
  131. }
  132.  
  133. function returnAccessibilityStr(){
  134.  
  135. return returnTag;
  136. }
  137.  
  138. ///////////////////////////////////////////////////////////////
  139. // functions
  140. //////////////////////////////////////////////////////////////
  141.  
  142. function isRadioButton(){
  143.     var pattern= /type="radio"/;
  144.     isradio= pattern.test(globalFormItem);
  145.     return isradio;
  146. }
  147.  
  148. function isCheckbox(){
  149.     var pattern= /type="checkbox"/;
  150.     ischeckbox= pattern.test(globalFormItem);
  151.     return ischeckbox;
  152. }
  153.  
  154. function addAttribute(tagName, tagVal, initStr){
  155.     arrayElem= initStr.split(">");
  156.   if (arrayElem.length == 1 || arrayElem[1] == ""){
  157.       rtnStr= arrayElem[0] + " " + tagName + "=" + '\"' + tagVal + '\"' + ">";
  158.   }else{
  159.       rtnStr= arrayElem[0] + " " + tagName + "=" + '\"' + tagVal + '\"' + ">" + arrayElem[1] + ">";
  160.   }
  161.     return rtnStr;
  162. }
  163.  
  164. function initialize(){
  165.  
  166.     theForm = document.forms[0];
  167.  
  168.     labelStyle= getLabelStyle();
  169.     if (labelStyle != 'none')
  170.     {theForm.labeloption[labelStyle].checked=true;}
  171.  
  172.     if (isCheckbox() || isRadioButton()) {    
  173.         theForm.position[1].checked=true;
  174.     } 
  175.     else {
  176.         theForm.position[0].checked=true;
  177.     }
  178.  
  179. }
  180.  
  181.  
  182. function getLabelStyle() {
  183.   var autoAdd, rtnValue = 'none';
  184.   var path = dreamweaver.getConfigurationPath() + '/Objects/Forms/AccessibilityOptions.js';
  185.   var metaFile;
  186.   metaFile = MMNotes.open(path, false);
  187.   if (metaFile) {
  188.  
  189.     autoAdd = MMNotes.get(metaFile, 'LABEL_style');
  190.     if (autoAdd) rtnValue = autoAdd;
  191.     MMNotes.close(metaFile);
  192.   }
  193.   return rtnValue;
  194. }
  195.  
  196.  
  197. function setLabelPref(setValue) {
  198.   var path = dreamweaver.getConfigurationPath() + '/Objects/Forms/AccessibilityOptions.js';
  199.   var metaFile;
  200.  
  201.   metaFile = MMNotes.open(path, true); // Force create the note file.
  202.   if (metaFile) {
  203.     if (setValue){
  204.  
  205.         autoAdd = MMNotes.set(metaFile, 'LABEL_style', setValue);
  206.     }
  207.     MMNotes.close(metaFile);
  208.   }
  209. }
  210.  
  211. function getElement(initStr){
  212.  
  213.     arrayElements= initStr.split("name=\"");
  214.     arrayStrings=  arrayElements[1].split("\"");
  215.     name= arrayStrings[0];
  216.     return name;
  217. }